//
//  Brands_BrandsMain_Collection_WX.m
//  ZITHER
//
//  Created by weixin on 2019/4/8.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "Brands_BrandsMain_Collection_WX.h"
#import "Brands_BrandsMainBrandList_CollectionViewCell_WX.h"
#import "Brands_BrandsMainBrandSpecial_CollectionViewCell_WX.h"

@implementation Brands_BrandsMain_Collection_WX


-(void)setArrTitle:(NSMutableArray *)arrTitle{
    _arrTitle = arrTitle;
    self.contentOffset = CGPointMake(0, 0);
    [self reloadData];
}


- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout{
    self = [super initWithFrame:frame collectionViewLayout:layout];
    if (self) {
        
        //CGRectMake(0,94, SCREEN_WIDTH, SCREEN_HEIGHT-137)
        
        self.delegate=self;
        
        self.dataSource=self;
        
        self.bounces=NO;
        
        self.pagingEnabled=YES;
        
        self.backgroundColor=[UIColor whiteColor];
        
        [self registerClass:[Brands_BrandsMainBrandList_CollectionViewCell_WX class] forCellWithReuseIdentifier:@"Brands_BrandsMainBrandList_CollectionViewCell_WX"];
        [self registerClass:[Brands_BrandsMainBrandSpecial_CollectionViewCell_WX class] forCellWithReuseIdentifier:@"Brands_BrandsMainBrandSpecial_CollectionViewCell_WX"];

        
        self.showsVerticalScrollIndicator = NO;
        
        self.showsHorizontalScrollIndicator = NO;
        //        BaseTbv Seach_FiltrateBrand_CollectionViewCell_WX
        
        
        
        _dicM = [NSMutableDictionary dictionary];
        
    }
    return self;
}


#pragma  mark--collection代理方法
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.arrTitle.count;
}

//创建复用tableView
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return [self getBrands_BrandsMainBrandList_CollectionViewCell_WX:indexPath];
    }else{
        return [self getBrands_BrandsMainBrandSpecial_CollectionViewCell_WX:indexPath];
    }
}

-(Brands_BrandsMainBrandList_CollectionViewCell_WX*)getBrands_BrandsMainBrandList_CollectionViewCell_WX:(NSIndexPath *)indexPath{
    Brands_BrandsMainBrandList_CollectionViewCell_WX *cell=[self dequeueReusableCellWithReuseIdentifier:@"Brands_BrandsMainBrandList_CollectionViewCell_WX" forIndexPath:indexPath];
    
    return cell;
}

-(Brands_BrandsMainBrandSpecial_CollectionViewCell_WX*)getBrands_BrandsMainBrandSpecial_CollectionViewCell_WX:(NSIndexPath *)indexPath{
    Brands_BrandsMainBrandSpecial_CollectionViewCell_WX *cell=[self dequeueReusableCellWithReuseIdentifier:@"Brands_BrandsMainBrandSpecial_CollectionViewCell_WX" forIndexPath:indexPath];
    cell.indexTbv = indexPath.row;
    cell.model = self.model.data[indexPath.row-1];
    return cell;
}





#pragma mark --  scrollView代理方法

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    //blockEndIndex
    NSLog(@"结束滑动  ===  %f",scrollView.contentOffset.x/kScreenW);
    NSInteger index = scrollView.contentOffset.x/kScreenW;
    _block(index);
    
}

- (BOOL)isPureInt:(NSString*)string{
    NSScanner* scan = [NSScanner scannerWithString:string];
    int val;
    return[scan scanInt:&val] && [scan isAtEnd];
}

- (BOOL)isPureNumandCharacters:(NSString *)string
{
    string = [string stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]];
    if(string.length > 0)
    {
        return NO;
    }
    return YES;
}

-(NSMutableArray *)setdic:(NSString*)index
{
    NSMutableArray *arrM =self.dicM[index];
    if (arrM ==nil) {
        arrM = [[NSMutableArray alloc]init];
        [self.dicM setObject:arrM forKey:index];
    }
    return arrM;
}

-(void)setDicM:(NSMutableDictionary *)dicM
{
    _dicM = dicM;
    [self reloadData];
}

-(void)setIndex:(NSInteger)index
{
    _index = index;
    [self reloadData];
}
-(void)setModel:(GoodsBrandTagstListModel *)model{
    _model = model;
    [self reloadData];
}

@end
